home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / util / pack / xpkrdcn21.lha / xpkRDCN / xpkrdcn.c < prev   
C/C++ Source or Header  |  1993-04-10  |  4KB  |  172 lines

  1.  
  2. /* These really aren't necessary.. */
  3. typedef unsigned char uchar;
  4. typedef unsigned short int uint;
  5.  
  6. #define NO_SUB_PRAGMAS
  7. #define A3000 XPKMF_A3000SPEED
  8. #define HASH_LEN 4096-1        /* Use a 4096 dictionary. If you ever
  9.                    think of changing this number you
  10.                    also have to modify the .asm-files.
  11.                                     */
  12. /* However, since this version only manage a gap of 4098 bytes, a larger
  13.    dictionary hardly improves compression. If you apply long-longpatterns
  14.    it might be usefull...
  15. */
  16.  
  17. #include <string.h>
  18. #include <stdlib.h>
  19.  
  20. #include <libraries/xpksub.h>
  21.  
  22.  
  23. /* Quick assembler unpack routine */
  24. long __asm unpack (register __a0 char *);
  25. uchar *__asm pack_one (register __a0 uint *, register __a1 uchar *,
  26.        register __a2 uchar *, register __a3 uchar *, register __a6 uchar **,
  27.                register __d6 uchar *);
  28.  
  29.  
  30. XMINFO RdcnMode =
  31. {
  32.   NULL,                /* next         */
  33.   100,                /* upto         */
  34.   A3000,            /* flags         */
  35.   4,                /* packmem         */
  36.   0,                /* unpackmem         */
  37.   200,                /* packspeed,   K/sec     */
  38.   900,                /* unpackspeed, K/sec     */
  39.   320,                /* ratio,      *0.1%     */
  40.   0,                /* reserved         */
  41.   "normal"            /* description         */
  42. };
  43.  
  44. static struct XpkInfo RdcnInfo =
  45. {
  46.   1,                /* info version */
  47.   0,                /* lib  version */
  48.   0,                /* master vers  */
  49.   0,                /* pad          */
  50.   "RDCN",            /* short name   */
  51.   "Ross Data Compression 2.1",    /* long name    */
  52.   "Packs fatser than BLZW, depacks faster than NUKE",    /* description    */
  53.   0x5244434e,            /* 4 letter ID  */
  54.   XPKIF_PK_CHUNK | XPKIF_UP_CHUNK,    /* flags        */
  55.   65535,            /* max in chunk */
  56.   0,                /* min in chunk */
  57.   65500,            /* def in chunk */
  58.   NULL,                /* pk message   */
  59.   NULL,                /* up message   */
  60.   NULL,                /* pk past msg  */
  61.   NULL,                /* up past msg  */
  62.   100,                /* def mode     */
  63.   0,                /* pad          */
  64.   &RdcnMode            /* modes        */
  65. };
  66.  
  67. /*
  68.  * Returns an info structure about our packer
  69.  */
  70. struct XpkInfo *__saveds __asm
  71. XpksPackerInfo (void)
  72. {
  73.   return &RdcnInfo;
  74. }
  75.  
  76.  
  77. void __saveds __asm
  78. XpksPackFree (REG __a0 XPARAMS * xpar)
  79. {
  80.   if (xpar->Sub[0] != 0)
  81.     {                /* Any dictionary-mem allocated? */
  82.       free ((char *) xpar->Sub[0]);
  83.       xpar->Sub[0] = 0;
  84.     }
  85. }
  86. /*
  87.  * This forces the next chunk to be uncompressable independent from the
  88.  * previous one. Ie. it clears the hash table
  89.  * This really shouldn't be necessary with RDCN, _but_ a future xpkmaster
  90.  * _might_ use different memory-chunks for every call to the packer.
  91.  */
  92. long __saveds __asm
  93. XpksPackReset (REG __a0 XPARAMS * xpar)
  94. {
  95.   char *ptr = (char *) xpar->Sub[0];
  96.   if (ptr != 0)
  97.     {
  98.       memset (ptr, 0, 4096 * sizeof (uchar **));
  99.     }
  100.  
  101.   return 0;
  102. }
  103.  
  104.  
  105. void __saveds __asm
  106. XpksUnpackFree (REG __a0 XPARAMS * xpar)
  107. {
  108.   /* Decompression does not need any additional data */
  109. }
  110.  
  111.  
  112. /* Pack a chunk */
  113.  
  114. long __saveds __asm
  115. XpksPackChunk (REG __a0 XPARAMS * xpar)
  116. {
  117.  
  118.   uchar **hash_tbl;
  119.   uint *ctrl_idx;
  120.   uchar *out_idx, *outbuff_end;
  121.   uchar *anchor;
  122.  
  123.   uchar *inbuff = xpar->InBuf;
  124.   uint inbuff_len = xpar->InLen;
  125.   uchar *outbuff = xpar->OutBuf;
  126.  
  127.   uchar *in_idx = inbuff;
  128.   uchar *inbuff_end = inbuff + inbuff_len;
  129.   hash_tbl = (char **) xpar->Sub[0];
  130.   ctrl_idx = (uint *) outbuff;
  131.  
  132.  
  133.     out_idx = outbuff + sizeof (uint);
  134.   outbuff_end = outbuff + xpar->OutBufLen - 48;
  135.  
  136.  
  137.  
  138.   if (xpar->Sub[0] == 0)
  139.     {
  140.  
  141.       xpar->Sub[0] = (long) calloc (4100, sizeof (uchar **));
  142.       hash_tbl = (char **) xpar->Sub[0];
  143.     }
  144.  
  145.  
  146.   /* Skip the compression for a small buffer */
  147.  
  148.   if (inbuff_len <= 18 || xpar->Sub[0] == 0)
  149.     return XPKERR_EXPANSION;
  150.  
  151.  
  152.   /* Scan through inbuff */
  153.  
  154.   anchor = pack_one (ctrl_idx, in_idx, out_idx, inbuff_end, hash_tbl, outbuff_end);
  155.  
  156.  
  157.   if (anchor == NULL)
  158.     return XPKERR_EXPANSION;
  159.  
  160.   xpar->OutLen = anchor - outbuff;
  161.   return 0;
  162. }
  163.  
  164. long __saveds __asm
  165. XpksUnpackChunk (REG __a0 XPARAMS * xpar)
  166. {
  167.   long fep;
  168.   fep = unpack ((char *)xpar);
  169.   return fep;
  170.  
  171. }
  172.